package com.kotlin.base.ui.activity

import android.os.Bundle
import com.kotlin.base.common.BaseApplication
import com.kotlin.base.injection.component.ActivityComponent
import com.kotlin.base.injection.component.DaggerActivityComponent
import com.kotlin.base.injection.module.ActivityModule
import com.kotlin.base.presenter.BasePresenter
import com.kotlin.base.presenter.view.BaseView
import com.kotlin.base.widgets.ProgressLoading
import javax.inject.Inject

/**
 * @author Mr.Wang
 * @version v0.3.6
 * @time 2018/3/7
 * @describe
 */
open abstract class BaseMvpActivity<T:BasePresenter<*>>: BaseActivity(),BaseView{

    private lateinit var mLoadingProgressBar: ProgressLoading

    override fun onError() {
    }

    override fun hideLoading() {
        mLoadingProgressBar.hideLoading()
    }

    override fun showLoading() {
        mLoadingProgressBar.showLoading()
    }

    @Inject
    lateinit var mPresenter:T

    lateinit var activityComponent:ActivityComponent


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        initActivityInject()
        initComponentInject()


        mLoadingProgressBar = ProgressLoading.create(this)
    }

    abstract fun initComponentInject()



    private fun initActivityInject() {
        activityComponent = DaggerActivityComponent.builder().appComponent((application as BaseApplication).appComponent).
                activityModule(ActivityModule(this)).build()
    }
}